package com.wxzz.elearning.common.constants;

import java.util.HashMap;
import java.util.Map;

/**
 * 全局的常量配置
 *
 * @author Zhang Jun
 */
public class CommonConstants {

    /**
     * 树结构层级分隔符
     */
    public final static String HIERARCHY_ID_SPLIT = "x";

    /**
     * 树结构根节点父ID
     */
    public final static int ROOT_PARENT_ID = 0;

    /**
     * 已删除
     */
    public static final Integer DELETE_TRUE = 1;

    /**
     * 未删除
     */
    public static final Integer DELETE_FALSE = 0;

    /**
     * 叶子节点
     */
    public static final Integer IS_LEAF_TRUE = 0;

    /**
     * 非叶子节点
     */
    public static final Integer IS_LEAF_FALSE = 1;

    /**
     * 启用
     */
    public static final String ENABLED_TRUE = "Y";

    /**
     * 禁用
     */
    public static final String ENABLED_FALSE = "N";

    /**
     * 是：Yes
     */
    public static final String YES = "Yes";

    /**
     * 否：No
     */
    public static final String NO = "No";

    /**
     * cookie 在redis中过期时间/秒
     */
    public static final int COOKIE_EXPIRED_PC = 2*60*60;
    public static final int COOKIE_EXPIRED_APP = 24*60*60;

    /**
     * profile表systemCode默认值
     */
    public static final String PROFILE_SYSTEM_CODE_DEFAULT_VALUE = "ALL";

    /**
     * 数据源类型
     */
    public static final String DATASOURCE_TYPE_DATABASE = "DataBase";

    /**
     * 数据源类型
     */
    public static final String DATASOURCE_TYPE_SOAP = "webServiceSOAP";

    /**
     * 数据源类型
     */
    public static final String DATASOURCE_TYPE_RESTFUL = "webServiceRestful";

    /**
     * 数据源访问类型
     */
    public static final String DATASOURCE_ACCESS_TYPE_MYSQL = "mysql";

    /**
     * 数据源访问类型
     */
    public static final String DATASOURCE_ACCESS_TYPE_ORACLE = "oracle";


    /**
     * 系统编码快码类型
     */
    public static final String DIC_TYPE_SYSTEM_CODE = "SYSTEM_CODE";

    /**
     * redis缓存管理类型
     */
    public static final String REDIS_CACHE_TYPE = "REDIS_CACHE_TYPE";

    /**
     * 虚拟仓库
     */
    public static final String VIRTUAL_WAREHOUSE = "00000";
    /**
     *用户启用状态代码
     */
    public static final Integer USER_STATUS_ENABLED = 1;
    /**
     *用户未启用状态代码
     */
    public static final Integer USER_STATUS_DISABLED = 0;
    /**
     * 设备使用状态
     */
    //正常
    public static final String DEVICE_USESTATUS_NORMAL = "normal";
    //维修中
    public static final String DEVICE_USESTATUS_REPAIR = "repairing";
    //保养中
    public static final String DEVICE_USESTATUS_MAINTAIN = "maintaining";
    //已报废
    public static final String DEVICE_USESTATUS_SCRAPED = "scraped";
    //停用
    public static final String DEVICE_USESTATUS_DISABLED = "disabled";
    /**
     * 设备维修处理状态
     */
    //未处理
    public static final String DEVICE_REPAIR_PROCESSSTATUS_UNSTART = "unstart";
    //已确认
    public static final String DEVICE_REPAIR_PROCESSSTATUS_COMFIRMED = "comfirmed";
    //不处理
    public static final String DEVICE_REPAIR_PROCESSSTATUS_UNHANDLE = "unhandle";
    //已处理
    public static final String DEVICE_REPAIR_PROCESSSTATUS_HANDLED = "handled";
    //已关闭
    public static final String DEVICE_REPAIR_PROCESSSTATUS_CLOSED = "closed";
    //处理中
    public static final String DEVICE_REPAIR_PROCESSSTATUS_HANDLING = "handling";
    //用户默认密码缓存key
    public static final String USER_DEFAULT_PASSWORD_CACHE_KEY = "user:default_password";
    //用户默认密码(缓存中设置的默认密码为空时使用)
    public static final String USER_DEFAULT_PASSWORD = "iot123";
    /**
     * 生产计划发布状态
     */
    //未发布
    public static final String PRODUCTION_PLAN_RELEASE_STATUS_UNRELEASE = "unrelease";
    //已发布
    public static final String PRODUCTION_PLAN_RELEASE_STATUS_RELEASED = "released";
    /**
     * 精工端租户ID
     */
    public static final Long TENANTID_JG = -999L;
    /**
     * 是否设备使用：否
     */
    public static final Byte DEVICEUSE_NO=0 ;
    /**
     * 是否设备使用：是
     */
    public static final Byte DEVICEUSE_YES=1 ;

    /**
     * 普通阈值，即只有最大值最小值
     */
    public static final Integer NORMAL_THRESHOLD = 1;
    /**
     * 特殊阈值，除最大值最小值外，还有监控点
     */
    public static final Integer SPECIAL_THRESHOLD = 2;
    public static final String CAUSE_ITEMS = "cause";

    public static final Integer AND_RELATION = 1;
    public static final Integer OR_RELATION = 2;
    /**
     * 分类标识正常
     */
    public static final Integer CLASS_TYPE_NORMAL=1;
    /**
     * 分类标识异常
     */
    public static final Integer CLASS_TYPE_ABNORMAL=0;

    /**
     * 工单状态
     */
    //拟定
    public static final Integer EAM_WORK_ORDER_STATUS_DRAW_UP=0;
    //待分配
    public static final Integer EAM_WORK_ORDER_STATUS_TOBE_ALLOCATED=1;
    //待维护
    public static final Integer EAM_WORK_ORDER_STATUS_PENDING_MAINTENANCE=2;
    //待确认
    public static final Integer EAM_WORK_ORDER_STATUS_TOBE_CONFIRMED=3;
    //关闭
    public static final Integer EAM_WORK_ORDER_STATUS_CLOSE=4;


    /**
     * Redis缓存KEY常量值
     */
    public interface RedisCacheKey {
        /**
         * 数据字典缓存Key，KEY：字典类型_系统编码
         */
        String BASE_LOOKUP_DATA_KEY_BY_LOOKUPTYPE = "BASE_LOOKUP_DATA_KEY_BY_LOOKUPTYPE";
        /**
         * 数据字典缓存Key，KEY：字典行表ID
         */
        String BASE_LOOKUP_DATA_KEY_BY_LOOKUPVALUEID = "BASE_LOOKUP_DATA_KEY_BY_LOOKUPVALUEID";
        /**
         * 全局的Redis缓存
         */
        String GLOBAL_REDIS_CACHE = "GLOBAL_REDIS_CACHE";
        /**
         * 最后一次同步更新时间
         * 用于保存在redis中同步的时间，使用hash保存
         */
        String LAST_SYNC_TIME = "LAST_SYNC_TIME";
        /**
         * 产品在redis中缓存的KEY
         */
        String BASE_PRODUCT_INFO_BY_ITEM_ID_KEY = "BASE_PRODUCT_INFO_BY_ITEM_ID";
        /**
         * 产品在redis中缓存的KEY
         */
        String BASE_PRODUCT_INFO_BY_ITEM_CODE_KEY = "BASE_PRODUCT_INFO_BY_ITEM_CODE";

        /**
         * 子库在redis缓存中的KEY
         */
        String BASE_WAREHOUSE_MAPPING_KEY = "BASE_WAREHOUSE_MAPPING";

        /**
         * 库存组织在redis缓存中的KEY
         */
        String BASE_ORGANIZATION_INV_VIEW_KEY = "BASE_ORGANIZATION_INV";

        /**
         * 组织机构最后同步时间在redis缓存中的KEY
         */
        String BASE_ORGANIZATION_SYNC_KEY = "BASE_ORGANIZATION_SYNC";

        /**
         * 保存当前用户所在产线和工位key
         */
        String LINE_STATION_CACHE_KEY = "LINE_STATION_CACHE";

    }

    public static final String TOKEN_TYPE_OPENAPI = "openApi";

    /**
     * 数据源驱动
     */
    public static final Map<String, String> DATASOURCE_DRIVER = new HashMap<>();

    public static final Map<String, String> SQL_DATA_TYPES = new HashMap<>();

    static {
        //数据库驱动
        DATASOURCE_DRIVER.put(DATASOURCE_ACCESS_TYPE_MYSQL, "com.mysql.jdbc.Driver");
        DATASOURCE_DRIVER.put(DATASOURCE_ACCESS_TYPE_ORACLE, "oracle.jdbc.driver.OracleDriver");
        //数据库字段类型
        SQL_DATA_TYPES.put("TINYINT", "NUMBER");
        SQL_DATA_TYPES.put("SMALLINT", "NUMBER");
        SQL_DATA_TYPES.put("MEDIUMINT", "NUMBER");
        SQL_DATA_TYPES.put("INTEGER", "NUMBER");
        SQL_DATA_TYPES.put("INT", "NUMBER");
        SQL_DATA_TYPES.put("BIGINT", "NUMBER");
        SQL_DATA_TYPES.put("FLOAT", "DOUBLE");
        SQL_DATA_TYPES.put("DOUBLE", "DOUBLE");
        SQL_DATA_TYPES.put("DECIMAL", "DOUBLE");
        SQL_DATA_TYPES.put("DATE", "DATE");
        SQL_DATA_TYPES.put("DATETIME", "DATETIME");
        SQL_DATA_TYPES.put("TIMESTAMP", "DATETIME");
    }
    //数据字典级别system/user:系统级/用户级
    public static final String DIC_GRADE_SYSTEM = "system";
    public static final String DIC_GRADE_USER= "user";

    /**
     * 短信事件类型
     */
    public static enum SMS_EVENTTYPE {

        REGISTRY(1,"REGISTRY"),
        FORGETPASSWORD(2,"FORGETPASSWORD"),
        PHONELOGIN(3,"PHONELOGIN"),
        DEVICEALARM (10,"DEVICEALARM");

        private Integer code;
        private String value;

        private  SMS_EVENTTYPE(Integer code,String value) {
            this.code = code;
            this.value = value;
        }

        public Integer getCode() {
            return code;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        /**
         * 根据code获取去value
         * @param code
         * @return
         */
        public static String getValueByCode(Integer code){
            for(SMS_EVENTTYPE eventtype:SMS_EVENTTYPE.values()){
                if(code.equals(eventtype.getCode())){
                    return eventtype.getValue();
                }
            }
            return  null;
        }

    }

}

